package org.example.lotterysystem.dao.mapper;

import org.apache.ibatis.annotations.*;
import org.example.lotterysystem.dao.dataobject.PrizeDO;

import java.util.List;

@Mapper
public interface PrizeMapper {
    /**
     * 查询总量
     * @return
     */
    @Select("Select count(*) from prize")
    Integer count();

    /**
     * 查询所有的奖品
     * @param offset
     * @param pageSize
     * @return
     */
    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDO> selectPrizeList(Integer offset, Integer pageSize);

    /**
     * 上传奖品
     * @param prizeDO
     * @return
     */
    @Insert("insert into prize(name,iamge_url,price,description) values (#{name},#{imageUrl},#{price},#{description})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Long insert(PrizeDO prizeDO);
    @Select("<script>select id from prize where id in " +
            "<foreach item='items' collection='items' open='('separator=',' close=')' #{items} </foreach> </script> ")
    List<Long> selectExistsByIds(@Param("items") List<Long> prizeIds);

    @Select("<script>select * from prize where id in " +
            "<foreach item='items' collection='items' open='('separator=',' close=')' #{items} </foreach> </script> ")
    List<PrizeDO> batchSelectByIds(@Param("items") List<Long> Ids);

    @Select("select * from prize where id=#{prizeId}")
    PrizeDO selectById(@Param("prizeId") Long prizeId);
}
